home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / c / ExtrasLib.lha / ExtrasLib / Examples / Thread_Test / Test.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  1.8 KB  |  90 lines

  1. #define DEBUG
  2. #include <debug.h>
  3.  
  4.  
  5. #include <extras/threads.h>
  6. #include <clib/extras/thread_protos.h>
  7. #include <proto/intuition.h>
  8. #include <proto/exec.h>
  9. #include <proto/gadtools.h>
  10. #include <proto/graphics.h>
  11. #include <proto/diskfont.h>
  12. #include <proto/dos.h>
  13. #include <stdio.h>
  14. #include <exec/memory.h>
  15. #include <stdlib.h>
  16.  
  17. void __asm __saveds myMsgHandler(register __a0 struct Thread *T,
  18.                                  register __a1 struct ThreadMessage *Msg);
  19.  
  20. void main(void)
  21. {
  22.   struct MsgPort *mp;
  23.   struct Thread *t;
  24.   struct ThreadMessage m;
  25.   
  26.   if(mp=CreateMsgPort())
  27.   {
  28.     DKP("Starting Thread\n");
  29.     if(t=thread_StartThread(TA_MsgHandler,  myMsgHandler,
  30.                         0))
  31.     {
  32.       DKP("Thread Running\n");
  33.  
  34.       m.tm_Command=1;
  35.       m.tm_Msg.mn_ReplyPort=mp;
  36.       m.tm_Msg.mn_Length=sizeof(m);
  37.  
  38.       Delay(50);
  39.       
  40.       DKP("Putting a Message\n");
  41.       thread_PutTMsg(t, &m);
  42.       WaitPort(mp);
  43.       DKP("  replied\n");
  44.  
  45.       Delay(50);
  46.  
  47.       DKP("Putting another Message\n");
  48.       m.tm_Command=20;
  49.       thread_PutTMsg_TagList(t, 20, TAG_DONE);
  50. //      WaitPort(mp);
  51.       DKP("  replied\n");
  52.  
  53.       Delay(50);
  54.       
  55.       DKP("Ending Thread\n");
  56.       thread_EndThread(t,0);
  57.       DKP("  Thread ended\n");
  58.       Delay(50);
  59.  
  60.     }
  61.     DeleteMsgPort(mp);
  62.   }
  63. }
  64.  
  65. void __asm __saveds myMsgHandler(register __a0 struct Thread *T,
  66.                                  register __a1 struct ThreadMessage *Msg)
  67. {
  68. //  printf("Msg Command=%d\n",Msg->tm_Command);
  69.  
  70.   switch(Msg->tm_Command)
  71.   {
  72.     case 1:
  73.       DKP("Command 1: Delay(120);\n");
  74.       Delay(60 * 2);
  75.       break;
  76.       
  77.     case 20:
  78.       DKP("Command 20:\n");
  79.       Delay(50);
  80.       break;
  81.       
  82.     case TMSG_DIE:
  83.       Delay(30);
  84. //      DKP("Ahhhh, you've killed me\n");
  85.       break;
  86.   }      
  87.  
  88. //  ReplyMsg((struct Message *)Msg);
  89. }
  90.